home *** CD-ROM | disk | FTP | other *** search
/ JCSM Shareware Collection 1993 November / JCSM Shareware Collection - 1993-11.iso / cl720 / sst115j.lzh / IDEMO.C < prev    next >
C/C++ Source or Header  |  1992-07-16  |  6KB  |  150 lines

  1. /* ------------------------------------------------------------------------ */
  2. /*                                 idemo.c                                  */
  3. /*                        demo on input entry fields                        */
  4. /* ------------------------------------------------------------------------ */
  5. #include <dos.h>
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <mem.h>
  9. #include <stdlib.h>
  10. #include <conio.h>
  11.  
  12. #include "sstkey.h"
  13. #include "sstwin.h"
  14.  
  15.  
  16. /* ------------------------------------------------------------------------ */
  17. /*                              function prototypes                         */
  18. /* ------------------------------------------------------------------------ */
  19. void          main                (void);
  20. int           endstroke           (int c);
  21.  
  22.  
  23. /* ------------------------------------------------------------------------ */
  24. /*                         structures used for demo                         */
  25. /* ------------------------------------------------------------------------ */
  26. typedef struct _info {
  27.    int  x;                  /* x coordinate of the input prompt */
  28.    int  y;                  /* x coordinate of the input prompt */
  29.    int  (*fvalid)(char *);  /* field validation function    */
  30.    void (*fhelp) (char *);  /* field help function */
  31.    int  fht;                /* filed help type */
  32.    int  ft;                 /* field type */
  33.    int  fa;                 /* field entry conversion attribute */
  34.    char *name;              /* fields name */
  35.    char *mask;
  36. } RECORD;
  37.  
  38. #define  RCOUNT    11
  39.  
  40. RECORD r[RCOUNT] =  {
  41.    { 1, 0,  NULL,          NULL,      HELP_KEYED,   FLD_ALNUM,  FLD_LJUST,
  42.      "Alpha & Numeric :", "_______________________________" },
  43.    { 1, 1,  NULL,          NULL,      HELP_KEYED,   FLD_ALPHA,  FLD_LJUST,
  44.      "Alpha           :", "_______________________________" },
  45.    { 1, 2,  NULL,          NULL,      HELP_KEYED,   FLD_DIGIT,  FLD_LJUST,
  46.      "Digit           :", "_______________________________" },
  47.    { 1, 3,  NULL,          NULL,      HELP_KEYED,   FLD_ASCII,  FLD_LJUST,
  48.      "Ascii           :", "_______________________________" },
  49.    { 1, 4,  NULL,          NULL,      HELP_KEYED,   FLD_PRINT,  FLD_LJUST,
  50.      "Printable       :", "_______________________________" },
  51.    { 1, 5,  NULL,          NULL,      HELP_KEYED,   FLD_XDIGIT, FLD_LJUST,
  52.      "HeX             :", "__________" },
  53.    { 1, 6,  NULL,          NULL,      HELP_KEYED,   FLD_CURR,  FLD_ZFILL,
  54.      "Currency        :", "$___.__" },
  55.    { 1, 7,  NULL,          NULL,      HELP_KEYED,   FLD_ASCII,  FLD_RJUST,
  56.      "Ascii R-Just    :", "_______________________________" },
  57.    { 1, 8,  NULL,          NULL,      HELP_KEYED,   FLD_ASCII,  FLD_LJUST |
  58.                                 FLD_TOUPPER,
  59.      "Ascii to-upper  :", "_______________________________" },
  60.    { 1, 9,  NULL,          NULL,      HELP_KEYED,   FLD_ASCII,  FLD_LJUST |
  61.                                 FLD_TOLOWER,
  62.      "Ascii to-lower  :", "_______________________________" },
  63.    { 1, 10, NULL,          NULL,      HELP_KEYED,   FLD_ASCII,  FLD_LJUST |
  64.                                 FLD_TOPROPER,
  65.      "Ascii to-proper :", "_______________________________" }
  66. };
  67.  
  68.  
  69.  
  70. /* ------------------------------------------------------------------------ */
  71. /* this structure is extremely inefficient but still ive used it for the    */
  72. /* sake of the demo                                                         */
  73. /* ------------------------------------------------------------------------ */
  74. char *drec[RCOUNT] = {
  75.          "                              ",
  76.          "                              ",
  77.          "                              ",
  78.          "                              ",
  79.          "                              ",
  80.          "           ",
  81.          "     ",
  82.          "                              ",
  83.          "                              ",
  84.          "                              ",
  85.          "                              "
  86. };
  87.  
  88. /* ------------------------------------------------------------------------ */
  89. /*                     test for an ending keystroke                         */
  90. /* this function is used to overide the default ending keystroke function   */
  91. /* ------------------------------------------------------------------------ */
  92. int endstroke(int c)
  93. {
  94.     switch (c)    {
  95.     case '\r':
  96.     case '\n':
  97.     case '\t':
  98.     case ESC:
  99.     case F8:
  100.     case F9:
  101.     case F10:
  102.     case PGUP:
  103.     case PGDN:
  104.     case HOME:
  105.     case END:
  106.     case UP:
  107.     case DOWN:
  108.         return TRUE;
  109.     default:
  110.         return FALSE;
  111.     }
  112. }
  113.  
  114. /* ------------------------------------------------------------------------ */
  115. void main(void)
  116.  
  117. {
  118.     WINDOW *wnd;
  119.     FIELD  *fld;
  120.     int c, ch = 0;
  121.  
  122.     if ((wnd = Westablish(10, 5, 13, 54)) == NULL)
  123.     return;
  124.     Wsettitle(wnd, "[Input Field Demo]",JUST_C);
  125.     Wsetcolour(wnd, WIN_BORDER,  LIGHTGRAY, WHITE, BRIGHT);
  126.     Wsetcolour(wnd, WIN_TITLE,   LIGHTGRAY, BLUE,  DIM);
  127.     Wsetcolour(wnd, WIN_FACE,    LIGHTGRAY, BLACK, DIM);
  128.     Wsetcolour(wnd, WIN_ACCENT,  GREEN,     BLACK, DIM);
  129.     Wsetcolour(wnd, WIN_FLDFACE, LIGHTGRAY, RED,   DIM);
  130.     Wshow(wnd);
  131.  
  132.     Finittemplate(wnd);
  133.     for (c = 0 ; c < RCOUNT ; c++)  {
  134.        Wprompt(wnd, r[c].x, r[c].y, r[c].name);
  135.        fld = Festablish(wnd, r[c].x+18, r[c].y, r[c].mask,
  136.                 drec[c], r[c].ft,r[c].fa);
  137.        if (r[c].fvalid)
  138.          Fpostvalidate(fld, r[c].fvalid);
  139.        if (r[c].fhelp)
  140.          Fhelpfunc(fld, r[c].fhelp,r[c].fht);
  141.     }
  142.     Fendfunc(endstroke);
  143.     while ((ch != ESC) && (ch != F10))
  144.        ch = Fdataentry(wnd,0);
  145.     Wdelete(wnd);
  146. }
  147.  
  148.  
  149.  
  150.